var tools = {
	// 验证手机号
	isphone(phone) {
		if (!(/^1[3456789]\d{9}$/.test(phone))) {
			return false;
		}
		return true;
	},

	//加载中
	loading() {
		uni.showLoading({
			'title': '加载中'
		})
	},
	onReachBottom(e) {
		this.pageData++
		this.teamInfo()
		// console.log('触底！！！')
	},
	//结束加载
	hideLoading() {
		uni.hideLoading()
	},
	//复制
	copyTextH5(info) {
		// #ifdef APP-PLUS
		uni.setClipboardData({
			//准备复制的数据
			data: info + '',
			success: function(res) {
				uni.showToast({
					title: '复制成功',
				});
			}
		})
		// #endif

		// #ifdef H5
		let result
		let textarea = document.createElement("textarea")
		textarea.value = info
		textarea.readOnly = "readOnly"
		document.body.appendChild(textarea)
		textarea.select() // 选中文本内容
		textarea.setSelectionRange(0, info.length) // 设置选定区的开始和结束点

		result = document.execCommand("copy") //将当前选中区复制到剪贴板
		console.log('[result]', result);
		if (result) {
			uni.showToast({ //提示
				title: '复制成功'
			})
		} else {
			uni.showToast({ //提示
				title: '复制失败，请重新尝试',
				icon: 'none'
			})
		}
		textarea.remove()
		// #endif
	},
	//图片转base64
	urlTobase64(url) {
		// #ifdef MP-WEIXIN
		uni.getFileSystemManager().readFile({
			filePath: url, //选择图片返回的相对路径
			encoding: 'base64', //编码格式
			success: res => { //成功的回调
				console.log(res);
				let base64 = 'data:image/jpeg;base64,' + res.data //不加上这串字符，在页面无法显示的哦
				let data = {
					base64: res.data,
					imgUrl: base64,
					url: url
				}
				return data
			},
			fail: (e) => {
				console.log("图片转换失败");
			}
		})
		// #endif

		// #ifndef MP-WEIXIN
		uni.request({
			url: url,
			method: 'GET',
			responseType: 'arraybuffer',
			success: ress => {
				let base641 = wx.arrayBufferToBase64(ress.data); //把arraybuffer转成base64 
				let base64 = 'data:image/jpeg;base64,' + base641 //不加上这串字符，在页面无法显示的哦
				let data = {
					base64: base641,
					imgUrl: base64,
					url: url
				}
				return data
			},
			fail: (e) => {
				console.log("图片转换失败");
			}
		})
		// #endif

	},




	fordataInfo(data) {
		let show = true
		for (let key in data) {
			const value = data[key]
			if (!value) {
				uni.showToast({
					title: '未填写完整',
					icon: 'none'
				})
				console.log('未填写完整', value, 'jhkgkjgkj拉萨看得见韩国')
				show = false;
				break;
			}
		}
		return show;
	},

	isEmail(email) {
		if (email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
			return true;
		else
			return false;
	},
	//跳转
	Router(index) {
		uni.navigateTo({
			url: index
		})
	},
	//跳转
	goNext(index) {
		uni.navigateTo({
			url: index
		})
	},
	//跳转
	push(index) {
		uni.navigateTo({
			url: index
		})
	},

	//获取订单编号
	getOrderNumber() {
		var timestamp = Date.parse(new Date());
		var Range = 100 - 1;
		var Rand = Math.random();
		return timestamp + (1 + Math.round(Rand * Range));
	},
	//获取随机数
	getSuiji() {
		var Range = Max - Min;
		var Rand = Math.random();
		return (Min + Math.round(Rand * Range));
	},
	//轻提示
	showToast(txt) {
		uni.showToast({
			title: txt,
			'icon': 'none'
		})
	},
	showToast2(txt) {
		uni.showToast({
			title: txt,
		})
	},
	//跳转到上一层页面
	back() {

		if (getCurrentPages().length < 2 || 'undefined' !== typeof __wxConfig) {
			let url = '/'
			uni.reLaunch({
				url: url
			})
		} else {
			uni.navigateBack({
				delta: 1
			});
		}



	},
	// 返回上一页
	goBack(num) {
		uni.navigateBack({
			delta: num
		})
	},
	//计算多长时间前
	getDateDiff(dateTimeStamp) {
		var minute = 1000 * 60;
		var hour = minute * 60;
		var day = hour * 24;
		var halfamonth = day * 15;
		var month = day * 30;
		var year = day * 365;
		var now = new Date().getTime();
		var diffValue = now - dateTimeStamp;
		if (diffValue < 0) {
			return;
		}
		var yearC = diffValue / year;
		var monthC = diffValue / month;
		var weekC = diffValue / (7 * day);
		var dayC = diffValue / day;
		var hourC = diffValue / hour;
		var minC = diffValue / minute;
		if (yearC >= 1) {
			result = "" + parseInt(yearC) + "年前";
		}
		if (monthC >= 1) {
			result = "" + parseInt(monthC) + "月前";
		} else if (weekC >= 1) {
			result = "" + parseInt(weekC) + "周前";
		} else if (dayC >= 1) {
			result = "" + parseInt(dayC) + "天前";
		} else if (hourC >= 1) {
			result = "" + parseInt(hourC) + "小时前";
		} else if (minC >= 1) {
			result = "" + parseInt(minC) + "分钟前";
		} else
			result = "刚刚";
		return result;
	},
	timestampToTime(timestamp) {
		var date = new Date(timestamp); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
		var Y = date.getFullYear() + '-';
		var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
		var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
		var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
		var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
		var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
		return Y + M + D + h + m + s;
	},



}

//将时间戳转换成正常时间格式
export default tools;
